//
//  FirstUserRingAlertController.swift
//  DaRings
//
//  Created by HFY on 2022/12/4.
//

import UIKit
import MYModule

class DeviceChargeReminderController: ViewController {
    
    static let connectedUserKey = "firstConnectUserKey"
    
    let gifImageView = ImageView()
    
    let titleLabel = Label()
    
    let descLabel = Label()
    
    let okButton = Button(type: .custom)
    
    /// 是否曾经连接过
    static var connected: Bool {
        
        return UserDefaults.standard.bool(forKey: connectedUserKey)
        
    }
    
    
    required init() {
        super.init(nibName: nil, bundle: nil)
        
        self.modalTransitionStyle = .crossDissolve
        self.modalPresentationStyle = .fullScreen
        
    }
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    override func viewDidLoad() {
        super.viewDidLoad()
        
        UserDefaults.standard.set(true, forKey: Self.connectedUserKey)
        
    
    }
    
    override func makeUI() {
        super.makeUI()
        
        let path = Bundle.main.path(forResource: "charging", ofType: "gif")
        let url = URL(fileURLWithPath: path!)
        gifImageView.contentMode = .scaleAspectFit
        gifImageView.sd_setImage(with: url)
//        gifImageView.backgroundColor = UIColor.assist_F8F8F8
        gifImageView.layer.cornerRadius = 20
        
        titleLabel.text = "device_tip_bind_title".language
        titleLabel.textColor = UIColor.assist_222222
        titleLabel.font = Fonts.boldSystemFont(ofSize: 24)
        
        descLabel.numberOfLines = 0
        descLabel.attributedText = "device_tip_bind_content".language.toAttributed
            .foregroundColor(UIColor.assist_A9A9A9)
            .font(Fonts.systemFont(ofSize: 16))
            .paragraph(setup: { $0.lineSpacing = 5 }).rawValue
        
        descLabel.textColor = UIColor.assist_A9A9A9
        descLabel.font = Fonts.systemFont(ofSize: 16)
        
    
        okButton.cornerRadius = 25.0
        okButton.setTitle("dialog_ok".language, for: .normal)
        okButton.setTitleColor(UIColor.assist_FFFFFF, for: .normal)
        okButton.backgroundColor = UIColor.theme
        
        okButton.rx.tap.subscribe(onNext: {[weak self] in
            
            self?.dismiss(animated: true)
            
        }).disposed(by: rx.disposeBag)
        
        view.addSubview(gifImageView)
        view.addSubview(titleLabel)
        view.addSubview(descLabel)
        view.addSubview(okButton)
        
        gifImageView.snp.makeConstraints { make in
            
            make.left.equalToSuperview().offset(20)
            make.right.equalToSuperview().offset(-20)
            make.height.equalTo(200)
            make.bottom.equalTo(titleLabel.snp.top).offset(-40)
        }
        
        titleLabel.snp.makeConstraints { make in
            make.left.equalTo(30)
            make.right.lessThanOrEqualToSuperview().offset(-30)
            make.bottom.equalTo(descLabel.snp.top).offset(-15)
        }
        
        descLabel.snp.makeConstraints { make in
            make.left.equalToSuperview().offset(30)
            make.right.equalToSuperview().offset(-30)
            make.bottom.equalTo(okButton.snp.top).offset(-65)
        }
        
        
        var bottom: CGFloat = 97
        if #available(iOS 11.0, *) {
            bottom = bottom + (UIApplication.shared.keyWindow?.safeAreaInsets.bottom ?? 0)
        }
        okButton.snp.makeConstraints { make in
            make.left.equalTo(50)
            make.right.equalTo(-50)
            make.height.equalTo(50)
            make.bottom.equalToSuperview().offset(-bottom)
        }
    }
    
    
    

    

}
